var core = require('core');
var db = core.db;
var send = core.send;

var isUser = function(req, res, next) {
    var body = req.body;
    body.tagid_list = body.tagid_list ? parseInt(body.tagid_list) : body.tagid_list;
    if(!body.tagid_list)
        delete body.tagid_list;

    for(var i in body){
        try{
            var param = JSON.parse(body[i]);
            body[i] = param;
        }catch(err){};
    };

    console.log(body);

    db.schema.User.findOne(body, function(err, user){
        var SEND;
        if(err)
            SEND = new send(100000);
        else if(!user)
            SEND = new send(100201);
        else{
            SEND = new send(0);
            SEND.docs = user;
        };
        res.send(SEND);
    });
};

module.exports = isUser;
